package com.wanmait.wanmarecruit.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wanmait.wanmarecruit.entity.Position;
import com.wanmait.wanmarecruit.mapper.PositionMapper;
import com.wanmait.wanmarecruit.service.EducationService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Queue;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wanmait.wanmarecruit.mapper.EducationMapper;
import com.wanmait.wanmarecruit.entity.Education;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(rollbackFor = Exception.class)
public class EducationServiceImpl extends ServiceImpl<EducationMapper, Education> implements EducationService {

    @Resource
    private EducationMapper educationMapper;

    @Resource
    private PositionMapper positionMapper;

    @Override
    public List<Education> getAllEducation() {
        LambdaQueryWrapper<Education> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(Education::getEducationName,Education::getId);
        return this.list(queryWrapper);
    }

    @Override
    public List<Education> getAllEducationAndPositionCount() {
        LambdaQueryWrapper<Education> lambdaQueryWrapper = new LambdaQueryWrapper();
        List<Education> educations = educationMapper.selectList(lambdaQueryWrapper);

        educations.forEach(education -> {
            LambdaQueryWrapper<Position> lambdaQueryWrapper1 = new LambdaQueryWrapper<>();
            lambdaQueryWrapper1.eq(Position::getEducationId,education.getId());
            Integer positionCount = positionMapper.selectCount(lambdaQueryWrapper1).intValue();
            education.setPositionCount(positionCount);
        });

        return educations;
    }
}
